package com.task.manage;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.task.job.meter3761.MeterDailyFreezing;
import com.task.job.meter3761.MeterHourse;
import com.task.job.water.WaterDailyFreezing;

/**
 * @ClassName: Job_Server
 * @Description: 任务管理的服务层
 * @author baozhijian
 * @date 2017年9月3日 下午3:20:17
 * @version V1.0
 */
@Service
public class Job_Server {
	private Logger logger = Logger.getLogger(Job_Server.class);

	@Autowired
	private JobManage jobManage;
	@Autowired
	private WaterDailyFreezing waterDailyFreezing;
	@Autowired
	private MeterDailyFreezing meterDailyFreezing;
	@Autowired
	private MeterHourse meterHourse;

	/**
	 * @Title: Job_Server.java
	 * @Description: 添加任务
	 * @param type
	 *            TODO
	 * @param taskid
	 * @param jobname
	 * @param jobgroup
	 * @param cronExpression
	 */
	public void Jobadd(int type, String job_type, String taskid, String cronExpression, String begintime,
			String endtime, String remark) {
		// 根据类型，选择任务

		switch (type) {
		case 1:
			// 电表任务
			switch (job_type) {
			case "1":// 电表日冻结

				jobManage.addjob(taskid, meterDailyFreezing, "job" + taskid + remark, "electric", cronExpression,
						begintime, endtime, remark);
				// logger.info(taskid + "-" + remark + "-" + date);
				break;
			case "2":// 实时数据
				jobManage.addjob(taskid, meterHourse, "job" + taskid + remark, "electric", cronExpression, begintime,
						endtime, remark);
				// logger.info(taskid + "-" + remark + "-" + date);
				break;
			default:
				break;
			}
			break;
		case 2:
			// 水表任务
			switch (job_type) {
			case "1":// 水表水量日冻结
				jobManage.addjob(taskid, waterDailyFreezing, "job" + taskid + remark + ":sent", "water", cronExpression,
						begintime, endtime, remark);
				break;
			default:
				break;
			}
			break;
		case 3:
			// 气表任务
			break;
		case 4:
			// 热表任务
			break;

		default:
			break;
		}

	}

	/**
	 * @Title: Job_Server.java
	 * @Description: 删除任务
	 * @param jobname
	 * @param jobgroup
	 */
	public void JobDelete(String jobname, String jobgroup) {
		jobManage.deleteJob(jobname, jobgroup);
	}

	public void Jobaddone(int type, String job_type, String taskid, String remark) {
		// 根据类型，选择任务
		switch (type) {
		case 1:
			// 电表任务
			switch (job_type) {
			case "1":// 电表日冻结

				Date date = jobManage.addjobforone(taskid, meterDailyFreezing, "jobforone" + taskid + remark,
						"electric", remark);
				logger.info(taskid + "-" + remark + "-" + date);
				break;
			default:
				break;
			}
			break;
		case 2:
			// 水表任务
			switch (job_type) {
			case "1":// 水表水量日冻结
				jobManage.addjobforone(taskid, waterDailyFreezing, "jobforone" + taskid + remark + ":sent", "water",
						remark);
				break;
			default:
				break;
			}
			break;
		case 3:
			// 气表任务
			break;
		case 4:
			// 热表任务
			break;

		default:
			break;
		}

	}

}
